<template>
    <div>
        <div class="rightBox">
          <span>总{{total}}条，共{{totalPage}}页&#x3000;每页大小</span>
          <el-select
            style="width: 80px;"
            @change="handleSizeChange()"
            size="mini"
            v-model="perpage"
            placeholder="请选择"
          >
            <el-option v-for="item in sizeOption" :key="item" :label="item" :value="item"></el-option>
          </el-select>
        </div>
        <button type="button" @click="handleCurrentChange(1);" class="btn-slot">
          <span>首页</span>
        </button>
        <el-pagination
            @current-change="handleCurrentChange"
            :current-page="page.pageNumber"
            :page-sizes="sizeOption"
            :page-size="pageSize"
            layout="prev, pager, next"
            prev-text="上一页"
            next-text="下一页"
            :total="total">
        </el-pagination>
        <button type="button" @click="handleCurrentChange(totalPage);" class="btn-slot">
          <span>末页</span>
        </button>
    </div>
</template>

<script>
  export default {
    name: 'pagination',
    props: {
        sizeOption: {
            type: Array,
            default() {
                return [5, 10, 15, 20, 25]
            }
        },
        pageSize: {
            type: Number,
            default() {
                return 5
            }
        },
        total: Number
    },
    data() {
      return {
        page: {
            currentPage: 1,
            pageNumber: 1
        },
        perpage: this.sizeOption[0]
      };
    },
    computed: {
      totalPage() {
        return Math.ceil( this.total / this.perpage )
      }
    },
    methods: {
      handleSizeChange() {
        this.handleCurrentChange(1);
      },
      handleCurrentChange(val) {
        this.page.pageNumber = val
        this.$emit('pageChange', { pageNo: val || 1, pageSize: this.perpage || 5})
      }
    }


  }
</script>

<style>
.el-pagination{
  display: inline-block;
  vertical-align: middle;
  margin-top: -1px;
}
.btn-slot{
  outline: none;
  margin: 2px 5px 0;
  background-color: #f4f4f5;
  color: #606266;
  min-width: 30px;
  border-radius: 2px;
  border: none;
  display: inline-block;
  font-size: 13px;
  min-width: 35.5px;
  height: 28px;
  line-height: 28px;
  vertical-align: top;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  cursor: pointer;
}
.el-pager li{
  margin: 0 5px;
  background-color: #f4f4f5;
  color: #606266;
  min-width: 30px;
  border-radius: 2px;  
}
.el-pager li.active{
  background-color: #409eff;
  color: #fff;  
}
.el-pagination .btn-next, .el-pagination .btn-prev{
  background: center center no-repeat #f4f4f5; 
}
.rightBox{
  display: inline-block;
  vertical-align: middle;
  margin-right: 10px;
}
</style>

